<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>主菜单</title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="css/mui.min.css">
		<link rel="stylesheet" href="css/semantic.css" />
		<link rel="stylesheet" href="css/mui.picker.css" />
		<link rel="stylesheet" href="css/mui.poppicker.css" />
		<link rel="stylesheet" type="text/css" href="css/font-awesome.css" />
	</head>
	<style type="text/css">
		/* 		#app {
			margin-top: 15%;
		} */

		.mui-card {
			background-image: linear-gradient(to bottom, #A4D3EE, white);
			background-color: #007AFF;
		}

		.m-btn {
			position: fixed;
			left: 0px;
			right: 0px;
			bottom: 10px;
			margin: auto;
			text-align: center;
			line-height: 30px;
			border-radius: 25px;
			width: 35%;
			height: 30px;
			background-color: whitesmoke;
			opacity: 0.7;
			border: 1px solid #B5B5B5;
		}
		
		.m-complete {
			padding-right: 20px;
			padding-left: 20px;
			font-size: 20px;
		}

		a {
			margin-top: 0.625rem;
		}

		#connectBtn {
			float: right;
		}

		#scanButton {
			float: left;
		}
		#closeTID{
			margin-left: 0.625rem ;
			float: left;
		}

		.content {
			margin-top: 12%;
		}
		
		span.mui-icon {
			font-size: 14px;
			color: #007aff;
			margin-left: -15px;
			padding-right: 10px;
		}
		
		.mui-popover {
			height: 300px;
		}
		
		.mui-content {
			padding: 10px;
		}
		#gro{
			overflow-y: auto;
		}
	</style>
	
	<body>
		<div id="app">
			<header class="mui-bar mui-bar-nav">
				<a id="scanButton" @click="send()">开始盘点</a>
				<a id="closeTID" @click="closeTID()">关闭TID</a>
				<h1 class="mui-title">盘点资产</h1>
				<a href="#blueToothList" id="connectBtn">连接蓝牙</a>
			</header>
			<div class="content" id="span_content">
				
			</div>
			<div id="blueToothList" class="mui-popover mui-popover-action ">
				<ul id="gro" class="mui-table-view" >
					<li class="mui-table-view">
						<div class="mui-table-view-cell" @click="startBlue">{{msg}}</div>
					</li>
					<li class="mui-table-view-cell" @click="ConnectDevice(index)" v-for="(item,index) in Pairedlist">
						{{item.bleName}}
					</li>
				</ul>
			</div>

		</div>
		<div id="inventory_bottom_menu" class="inventory_bottom_menu">
			<label class="m-btn">
				<span class="m-complete" id="complete"><i class="fa fa-hand-peace-o "></i></span>
				<a href="#bottomPopover"><span class="m-complete"><i class="fa fa-pencil-square-o"></i></span></a>
			</label>
		</div>
		<!--选择框组件-->
		<div id="bottomPopover" class="mui-popover mui-popover-bottom">
			<div class="mui-popover-arrow"></div>
			<div class="mui-scroll-wrapper">
				<div class="mui-scroll">
					<ul class="mui-table-view">
						<li class="mui-table-view-cell">
							<a href="#"></a>
							<label class="mui-h3">手动盘点</label> （二选一）
							<form class="mui-input-group">
								<div class="mui-input-row">
									<label>资产编号</label>
									<input type="text" name="handel_assetNum" id="handel_assetNum" class="mui-input-clear" placeholder="手动输入">
								</div>
								<div class="mui-input-row mui-plus-visible">
									<label>资产编号</label>
									<input type="text" class="mui-input-speech mui-input-clear" id="handel_assetNum_voice" placeholder="语音输入">
								</div>
								<div class="mui-button-row">
									<button class="mui-btn mui-btn-primary" type="button" onclick="handelinventory()">确认</button>&nbsp;&nbsp;
								</div>
							</form>
						</li>

					</ul>
				</div>
			</div>

		</div>

		<audio id="audio">
			<source src="audio/success.wav" type="audio/wav">
			您的浏览器不支持 audio 元素。
		</audio>
	</body>

</html>
<script type="text/javascript" src="js/mui.js"></script>
<script src="js/vue.js"></script>
<script src="js/addressinitialization.js"></script>
<script>
	mui.init();
	let connectDevice = null;
	let bleSocket = null;
	let timer = null;
	let connectId = null;
	let dataArr = new Array();
	const select_active_store = getRequest('select_active_store');

	// 扫描成功音频提示
	function audio_success() {
		document.getElementById("audio").play();
	}

	//开始扫描
	function start() {
		//mui.toast("开始扫描");
		//将扫描存放地存入域中
		var storeName = select_active_store;
		mui.ajax(IP + '/ias/AndroidInputAsset/setStoreName', {
			data: {
				storeName: storeName
			},
			type: 'post',
			dataType: 'json',
			timeout: 10000,
			headers: {
				'Content-Type': 'application/json'
			},
			error: function(xhr, type, errorThrown) {
				mui.toast("请求失败，请检查登陆状态");
			}
		});

	}

	// 预加载详情页
	mui.plusReady(function() {
		start(); 	// 写入扫描地
		complete_but(); //完成扫描
		mui.preload({
			url: 'complete_sub.html',
			id: 'complete_sub.html'
		});
		sub_page = plus.webview.getWebviewById('complete_sub.html');
	})

	// 监听跳转详情页
	function tap_sub_event() {
		mui(".mui-card").on('tap', '.mui-card-header', function() {
			var title = this.getAttribute("title");
			var id = this.getAttribute("id");
			mui.fire(sub_page, 'get_detail', {
				title_: title,
				id_: id
			});
		})
	}

	//主页返回键处理
	mui.back = function() {
		window.location = "mainPage.html";
	}

	//手动盘点
	function handelinventory() {
		var storeName = select_active_store;
		var assetNum = "";
		if (mui("#handel_assetNum_voice")[0].value === "") {
			assetNum = mui("#handel_assetNum")[0].value;
		}
		if (mui("#handel_assetNum")[0].value === "") {
			assetNum = mui("#handel_assetNum_voice")[0].value;
			console.log(mui("#handel_assetNum_voice")[0].value);
		}
		var Android_URL = IP + '/ias/AndroidInputAsset/InventoryProcess';
		if (assetNum == "") {
			mui.alert("请输入资产编号");
		} else {
			mui.ajax(Android_URL, {
				data: {
					assetNum: assetNum,
					storeName: storeName
				},
				type: 'post',
				dataType: 'json',
				headers: {
					'Content-Type': 'application/json'
				},
				success: function(response) {
					if (response.result == 'error') {
						mui.alert(response.msg);
					} else {
						/*获取后台数据*/
						var asset = response.data;
						if (asset.assetNum != null) {
							var assetNum = asset.assetNum; //资产编号
							var assetName = asset.assetName; //资产名称
							var inventoryStore = asset.inventoryStore; //存放地
							var inventoryDepart = asset.inventoryDepart; //部门
							var inventoryBatch = asset.inventoryBatch; //批次号
							var inventoryDate = asset.inventoryDate; //盘点时间
							var inventoryStatus = asset.inventoryStatus; //盘点状态
							var inventoryspanAdrr = asset.inventoryspanAdrr; //扫描地
							var admin = "陈少磊";
							/*是否已存在信息框*/
							var msg_div = document.getElementById(assetNum);
							if (msg_div == null) {
								/*动态添加信息框*/
								var parent = document.getElementById("span_content");
								var m_card = document.createElement('div');
								m_card.className = "mui-card";
								// 卡片header
								var m_card_header = document.createElement('div');
								m_card_header.className = "mui-card-header";
								m_card_header.title = assetName;
								m_card_header.id = assetNum;
								m_card_header.innerText = assetName;
								var m_card_header_span = document.createElement('span');
								m_card_header_span.className = "mui-right";
								var m_card_header_a = document.createElement('a');
								m_card_header_a.className = "mui-navigate-right";
								/*m_card_header_a.title = assetName;
								m_card_header_a.id = assetNum;*/
								m_card_header_span.appendChild(m_card_header_a);
								m_card_header.appendChild(m_card_header_span);

								//卡片content
								var m_card_content = document.createElement('div');
								m_card_content.className = "mui-card-content";
								var m_table = document.createElement('div');
								m_table.className = "m-table";

								// row1
								var m_c_row_1 = document.createElement('div');
								m_c_row_1.className = "mui-row";
								var m_c_row_1_col_1 = document.createElement('div');
								m_c_row_1_col_1.className = "mui-col-xs-8";
								var m_c_asset_id = document.createElement('h5');
								m_c_asset_id.className = "mui-ellipsis";
								m_c_asset_id.innerText = "资产编号";
								var m_c_asset_id_span = document.createElement('span');
								m_c_asset_id_span.innerText = assetNum;
								m_c_asset_id.appendChild(m_c_asset_id_span);
								m_c_row_1_col_1.appendChild(m_c_asset_id);
								var m_c_row_1_col_2 = document.createElement('div');
								m_c_row_1_col_2.className = "mui-col-xs-4";
								var m_c_asset_status = document.createElement('h5');
								m_c_asset_status.classList.add('mui-ellipsis', 'm-status');
								m_c_asset_status.innerText = inventoryStatus;
								m_c_row_1_col_2.appendChild(m_c_asset_status);
								m_c_row_1.appendChild(m_c_row_1_col_1);
								m_c_row_1.appendChild(m_c_row_1_col_2);

								//row2
								var m_c_row_2 = document.createElement('div');
								m_c_row_2.className = "mui-row";
								var m_c_row_2_col_1 = document.createElement('div');
								m_c_row_2_col_1.className = "mui-col-xs-6";
								var m_c_asset_store = document.createElement('p');
								m_c_asset_store.className = "mui-ellipsis";
								m_c_asset_store.innerText = "存放地：";
								var m_c_asset_store_span = document.createElement('span');
								m_c_asset_store_span.innerText = inventoryStore;
								m_c_asset_store.appendChild(m_c_asset_store_span);
								m_c_row_2_col_1.appendChild(m_c_asset_store);
								var m_c_row_2_col_2 = document.createElement('div');
								m_c_row_2_col_2.className = "mui-col-xs-6";
								var m_c_asset_spanaddr = document.createElement('p');
								m_c_asset_spanaddr.className = "mui-ellipsis";
								m_c_asset_spanaddr.innerText = "扫描地：";
								var m_c_asset_spanadder_span = document.createElement('span');
								m_c_asset_spanadder_span.innerText = inventoryspanAdrr;
								m_c_asset_spanaddr.appendChild(m_c_asset_spanadder_span);
								m_c_row_2_col_2.appendChild(m_c_asset_spanaddr);
								m_c_row_2.appendChild(m_c_row_2_col_1);
								m_c_row_2.appendChild(m_c_row_2_col_2);
								//row3
								var m_c_row_3 = document.createElement('div');
								m_c_row_3.className = "mui-row";
								var m_c_row_3_col_1 = document.createElement('div');
								m_c_row_3_col_1.className = "mui-col-xs-6";
								var m_c_time = document.createElement('p');
								var m_c_time_span = document.createElement('span');
								m_c_time_span.innerText = inventoryDate;
								m_c_time.appendChild(m_c_time_span);
								m_c_row_3_col_1.appendChild(m_c_time);
								var m_c_row_3_col_2 = document.createElement('div');
								m_c_row_3_col_2.className = "mui-col-xs-6";
								var m_c_admin = document.createElement('p');
								m_c_admin.className = "mui-ellipsis";
								m_c_admin.innerText = "盘点人：";
								var m_c_admin_span = document.createElement('span');
								m_c_admin_span.innerText = admin;
								m_c_admin.appendChild(m_c_admin_span);
								m_c_row_3_col_2.appendChild(m_c_admin);
								m_c_row_3.appendChild(m_c_row_3_col_1);
								m_c_row_3.appendChild(m_c_row_3_col_2);

								m_table.appendChild(m_c_row_1);
								m_table.appendChild(m_c_row_2);
								m_table.appendChild(m_c_row_3);
								m_card_content.appendChild(m_table);
								m_card.appendChild(m_card_header);
								m_card.appendChild(m_card_content);
								parent.insertBefore(m_card, parent.firstElementChild);

								mui.toast("手动盘点成功");
								tap_sub_event();
							} else {
								mui.toast("已盘点");
							}
						} else {
							mui.toast("不存在此资产");
						}
					}

				},
				error: function(xhr, textStatus, errorThrown) {
					mui.toast("数据错误，请检查登陆状态");
				}
			});
		}
	}

	//完成扫描
	function complete_but() {
		document.getElementById("complete").addEventListener("tap", function(e) {
			e.detail.gesture.preventDefault();
			var btnArray = ['否', '是'];
			mui.confirm("确认完成扫描？", "提示", btnArray, function(e) {
				if (e.index == 1) {
					window.location = "startinventory.html";
				} else {; //否
				}
			})
		})
	}


	// 获取NFC扫描的资产信息
	function getAssetInfo(assetNum, storeName) {
		//根据扫描所得资产编号获取资产信息
		mui.ajax(IP + '/ias/AndroidInputAsset/InventoryProcess', {
			data: {
				assetNum: assetNum,
				storeName: storeName
			},
			type: 'post',
			dataType: 'json',
			headers: {
				'Content-Type': 'application/json'
			},
			success: function(response) {
				if (response.result == 'error') {
					mui.alert(response.msg);
				} else {
					/*获取后台数据*/
					var asset = response.data;
					// console.log(asset);
					if (asset.assetNum != null) {
						var assetNum = asset.assetNum; //资产编号
						var assetName = asset.assetName; //资产名称
						var inventoryStore = asset.inventoryStore; //存放地
						var inventoryDepart = asset.inventoryDepart; //部门
						var inventoryBatch = asset.inventoryBatch; //批次号
						var inventoryDate = asset.inventoryDate; //盘点时间
						var inventoryStatus = asset.inventoryStatus; //盘点状态
						var inventoryspanAdrr = asset.inventoryspanAdrr; //扫描地
						var admin = "陈少磊";
						/*是否已存在信息框*/
						var msg_div = document.getElementById(assetNum);
						if (msg_div == null) {
							/*动态添加信息框*/
							var parent = document.getElementById("span_content");
							var m_card = document.createElement('div');
							m_card.className = "mui-card";
							// 卡片header
							var m_card_header = document.createElement('div');
							m_card_header.className = "mui-card-header";
							m_card_header.title = assetName;
							m_card_header.id = assetNum;
							m_card_header.innerText = assetName;
							var m_card_header_span = document.createElement('span');
							m_card_header_span.className = "mui-right";
							var m_card_header_a = document.createElement('a');
							m_card_header_a.className = "mui-navigate-right";
							/*m_card_header_a.title = assetName;
							m_card_header_a.id = assetNum;*/
							m_card_header_span.appendChild(m_card_header_a);
							m_card_header.appendChild(m_card_header_span);

							//卡片content
							var m_card_content = document.createElement('div');
							m_card_content.className = "mui-card-content";
							var m_table = document.createElement('div');
							m_table.className = "m-table";

							// row1
							var m_c_row_1 = document.createElement('div');
							m_c_row_1.className = "mui-row";
							var m_c_row_1_col_1 = document.createElement('div');
							m_c_row_1_col_1.className = "mui-col-xs-8";
							var m_c_asset_id = document.createElement('h5');
							m_c_asset_id.className = "mui-ellipsis";
							m_c_asset_id.innerText = "资产编号";
							var m_c_asset_id_span = document.createElement('span');
							m_c_asset_id_span.innerText = assetNum;
							m_c_asset_id.appendChild(m_c_asset_id_span);
							m_c_row_1_col_1.appendChild(m_c_asset_id);
							var m_c_row_1_col_2 = document.createElement('div');
							m_c_row_1_col_2.className = "mui-col-xs-4";
							var m_c_asset_status = document.createElement('h5');
							m_c_asset_status.classList.add('mui-ellipsis', 'm-status');
							m_c_asset_status.innerText = inventoryStatus;
							m_c_row_1_col_2.appendChild(m_c_asset_status);
							m_c_row_1.appendChild(m_c_row_1_col_1);
							m_c_row_1.appendChild(m_c_row_1_col_2);

							//row2
							var m_c_row_2 = document.createElement('div');
							m_c_row_2.className = "mui-row";
							var m_c_row_2_col_1 = document.createElement('div');
							m_c_row_2_col_1.className = "mui-col-xs-6";
							var m_c_asset_store = document.createElement('p');
							m_c_asset_store.className = "mui-ellipsis";
							m_c_asset_store.innerText = "存放地：";
							var m_c_asset_store_span = document.createElement('span');
							m_c_asset_store_span.innerText = inventoryStore;
							m_c_asset_store.appendChild(m_c_asset_store_span);
							m_c_row_2_col_1.appendChild(m_c_asset_store);
							var m_c_row_2_col_2 = document.createElement('div');
							m_c_row_2_col_2.className = "mui-col-xs-6";
							var m_c_asset_spanaddr = document.createElement('p');
							m_c_asset_spanaddr.className = "mui-ellipsis";
							m_c_asset_spanaddr.innerText = "扫描地：";
							var m_c_asset_spanadder_span = document.createElement('span');
							m_c_asset_spanadder_span.innerText = inventoryspanAdrr;
							m_c_asset_spanaddr.appendChild(m_c_asset_spanadder_span);
							m_c_row_2_col_2.appendChild(m_c_asset_spanaddr);
							m_c_row_2.appendChild(m_c_row_2_col_1);
							m_c_row_2.appendChild(m_c_row_2_col_2);
							//row3
							var m_c_row_3 = document.createElement('div');
							m_c_row_3.className = "mui-row";
							var m_c_row_3_col_1 = document.createElement('div');
							m_c_row_3_col_1.className = "mui-col-xs-6";
							var m_c_time = document.createElement('p');
							var m_c_time_span = document.createElement('span');
							m_c_time_span.innerText = inventoryDate;
							m_c_time.appendChild(m_c_time_span);
							m_c_row_3_col_1.appendChild(m_c_time);
							var m_c_row_3_col_2 = document.createElement('div');
							m_c_row_3_col_2.className = "mui-col-xs-6";
							var m_c_admin = document.createElement('p');
							m_c_admin.className = "mui-ellipsis";
							m_c_admin.innerText = "盘点人：";
							var m_c_admin_span = document.createElement('span');
							m_c_admin_span.innerText = admin;
							m_c_admin.appendChild(m_c_admin_span);
							m_c_row_3_col_2.appendChild(m_c_admin);
							m_c_row_3.appendChild(m_c_row_3_col_1);
							m_c_row_3.appendChild(m_c_row_3_col_2);

							m_table.appendChild(m_c_row_1);
							m_table.appendChild(m_c_row_2);
							m_table.appendChild(m_c_row_3);
							m_card_content.appendChild(m_table);
							m_card.appendChild(m_card_header);
							m_card.appendChild(m_card_content);
							parent.insertBefore(m_card, parent.firstElementChild);
							audio_success();
							mui.toast("盘点成功");
							tap_sub_event();
						} else {
							// mui.toast("已盘点");
						}
					} else {
						// mui.toast("不存在此资产");
					}
				}

			},
			error: function(xhr, textStatus, errorThrown) {
				// mui.toast("数据错误，请检查登陆状态");
				console.log("数据错误，请检查登陆状态");
			}
		});
	}

	// 获取选中的存放地（参数为：select_active_store）
	function getRequest(parameters) {
		var url = window.location.search; //获取url中"?"符后的字串   
		var theRequest = new Object();
		if (url.indexOf("?") != -1) {
			var str = url.substr(1);
			strs = str.split("&");
			for (var i = 0; i < strs.length; i++) {
				//就是这句的问题
				theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
			}
		}
		return theRequest[parameters];
	}

	// 将十六进制数组传为字符串
	function hex2String(hexArr) {
		let len = hexArr.length;
		let result = "";
		for (let i = 0; i < len; i++) {
			result += String(hexArr[i]);
		}
		return result;
	}

	// 十六进制数组转字符串
	function hexArr2String(hexArr) {
		var val = "";
		for (var i = 0; i < hexArr.length; i++) {
			val += String.fromCharCode(parseInt(hexArr[i], 16));
		}
		return val;
	}

	//十六进制字符串转字节数组
	function HexString2Bytes(str) {
		var pos = 0;
		var len = str.length;
		if (len % 2 != 0) {
			return 0;
		}
		len /= 2;
		var arrBytes = new Array();
		for (var i = 0; i < len; i++) {
			var s = str.substr(pos, 2);
			var v = parseInt(s, 16);
			arrBytes.push(v);
			pos += 2;
		}
		return arrBytes;
	}

	// 十六进制数组转字节数组
	function HexArr2Bytes(hexArr) {
		let bytes = new Array();
		let len = hexArr.length;
		for (var i = 0; i < len; i++) {
			bytes.push(Number(HexString2Bytes(hexArr[i])))
		}
		return bytes;
	}

	//字符串转十六进制数组
	function String2HexArr(str) {
		let value = new Array();
		for (var i = 0; i < str.length; i++) {
			if (value == "") {
				value.push(str.charCodeAt(i).toString(16));
			} else {
				value.push(str.charCodeAt(i).toString(16));
			}
		}
		return value;
	}

	// 字节数组转十六进制字符串
	function bytesToHexArr(inarray) {
		var i, j, x;
		var hex = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
			"B", "C", "D", "E", "F"
		];
		var inArr = new Array();
		for (j = 0; j < inarray.length; ++j) {
			var out = "";
			x = inarray[j] & 0xff;
			i = (x >> 4) & 0x0f;
			out += hex[i];
			i = x & 0x0f;
			out += hex[i];
			inArr.push(out)
		}
		return inArr;
	}

	// 将获取的十六进制数组转为数据字符串
	function hex2DataString(inArr) {
		// 获取数据长度
		let dataLen = inArr[0];
		let data = "";
		for (let i = 1; i <= dataLen; i++) {
			data += inArr[i];
		}
		// 数据中含有A统一替换为S
		data = data.replace('A', 'S')
		return data;
	}

	/*
	 * 获取某个元素下标
	 * arr: 传入的数组
	 * obj: 需要获取下标的元素
	 * */
	function getArrayIndex(arr, obj) {
		var i = arr.length;
		var indexArr = [];
		while (i--) {
			if (arr[i] === obj) {
				indexArr.unshift(i);
			}
		}
		return indexArr;
	}

	/**string2BytesArr
	 * @param {Object} str
	 */
	function string2Bytes(str) {
		let ch, st, re = [];
		for (var i = 0; i < str.length; i++) {
			ch = str.charCodeAt(i);
			st = [];
			do {
				st.push(ch & 0xFF);
				ch = ch >> 8;
			} while (ch);
			re = re.concat(st.reverse());
		}
		return re;
	}

	/**
	 * 是否完全包含另一个数组
	 * @param {Object} aa 小数组
	 * @param {Object} bb 大数组
	 */
	function isInclude(aa, bb) {
		return aa.every((item) => {
			return bb.some((sub) => {
				return sub === item;
			})
		})
	}

	// 数组是否重复
	function isRepeat(aArr, bArr) {
		for (let i = 0; i < aArr.length; i++) {
			if (isInclude(bArr, aArr[i])) {
				return false;
			}
		}
		return true;
	}

	/**
	 * 获取首个0后一位（EPC开头）到密码0前一位（EPC结束）的下标
	 * @param {Object} arr 0的下标数组
	 */
	function getDataFristToEndIndex(arr) {
		let len = arr.length;
		if (len <= 1) {
			return -1;
		}
		var end = 0;
		// 首个0的位置+1（EPC开头）
		let first = arr[0];
		let index = 0;
		for (let i = 0; i < len; i++) {
			if (i + 1 < 0) {
				if (arr[i + 1] - arr[i] === 1) {
					end = arr[i + 1];
					break;
				}
			}
		}
		return (end === 0) ? -1 : [first + 1, end - 1];
	}

	// bytes是否大于127或小于-128
	function ifB127SF128(arr) {
		for (let i = 0; i < arr.length; i++) {
			if (arr[i] > 127) {
				arr[i] = arr[i] - 256;
			} else if (arr[i] < (-128)) {
				arr[i] = arr[i] + 256;
			} else {
				arr[i] = arr[i];
			}
		}
		return arr;
	}

	// 设置天线
	function checkSum(arr, zero, len) {
		let btSum = 0;
		for (let nloop = zero; nloop < zero + len; nloop++) {
			if (parseInt(arr[nloop]) !== 0) {
				btSum += parseInt(arr[nloop]);
			}
		}
		let result = (~btSum) + 1;
		if (result > 127) {
			return result - 256;
		} else if (result < (-128)) {
			return result + 256;
		} else {
			return result;
		}
	}

	// 写入标签数据（格式处理）
	function setLable(str) {
		let arr = new Array();
		let len = str.length / 2;
		// 将数据长度写到首位
		arr.push(parseInt(len));
		// 将字符串中的S替换成A
		str = str.replace('S', 'A');
		if ((len % 2) === 0) {
			// 偶数
			let index = 0;
			do {
				len--;
				let c = str.substr(index, 2);
				let byt = HexString2Bytes(c);
				index += 2;
				if (byt > 127) {
					arr.push(parseInt(byt - 256));
				} else if (byt < (-128)) {
					arr.push(parseInt(byt + 256));
				} else {
					arr.push(parseInt(byt));
				}
			} while (len > 0)
		} else {
			// 偶数
			let index = 0;
			do {
				len--;
				let c = str.substr(index, 2);
				let byt = HexString2Bytes(c);
				index += 2;
				if (byt > 127) {
					arr.push(parseInt(byt - 256));
				} else if (byt < (-128)) {
					arr.push(parseInt(byt + 256));
				} else {
					arr.push(parseInt(byt));
				}
			} while (len > 0)
		}
		return arr;
	}

	//主页返回键处理
	mui.back = function() {
		window.location = "startinventory.html";
	}

	document.addEventListener("plusready", function() {
		var vm = new Vue({
			'el': "#app",
			data: function() {
				return {
					msg: '搜索蓝牙设备',
					isSearch: false, // 是否开始扫描蓝牙
					Pairedlist: [], // 已配对的蓝牙列表
					// Unpairedlist: [], // 未匹配的蓝牙列表
					blue: null, // 当前组件全局蓝牙类
					dataList: [{
						hex: null,
						arr: null
					}] //扫描标签列表
					// firmwareId: null, // 固件版本
					// temperature: null, // 工作温度
					// read_lableId: null, // 读取单个标签
					// select_lableId: null, // 选取单个标签
					// set_lableId: null, // 写入的标签
					// is_select: false
				}
			},
			methods: {
				closeTID:function(){
					try{
						if (bleSocket === null) {
							mui.toast("关闭失败！设备未连接！")
							return;
						}
						let bytes = [-96, 4, 1, -116, 0, -49]
						let invoke = plus.android.invoke;
						btOutStream = invoke(bleSocket, "getOutputStream");
						plus.android.importClass(bleSocket);
						plus.android.importClass(btOutStream);
						btOutStream.write(bytes);
						btOutStream.flush();
						btInStream = invoke(bleSocket, "getInputStream");
						plus.android.importClass(btInStream);
						let dataArr = new Array();
						while(1){
							let data = invoke(btInStream, "read");
							if(dataArr.length>1 && data==160){
								console.log(dataArr);
								break;
							}else{
								dataArr.push(data);
							}
						}
					}catch(err){
						mui.toast('关闭TID功能失败！');
					}
				},
				send:function(){
					let obj = document.getElementById("scanButton");
					if (bleSocket === null) {
						mui.toast("请连接蓝牙设备！");
						return;
					}
					if (timer === null) {
						if (bleSocket !== null || timer === null) {
							bleSocket.close();
							var plusMain = plus.android.runtimeMainActivity(), // Android原生应用的主Activity对象
								BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"), // 引入蓝牙设备操作类
								UUID = plus.android.importClass("java.util.UUID"), // 引入生成UUID类
								// uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
								uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
								BAdapter = BluetoothAdapter.getDefaultAdapter(), // 获得蓝牙适配器实例
								device = BAdapter.getRemoteDevice(connectId); // 以给定的MAC地址去创建一个 BluetoothDevice 类实例(代表远程蓝牙实例)。
							BAdapter.cancelDiscovery();
							plus.android.importClass(device); // 引入 BluetoothDevice 类实例 方便 . 操作
							var bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); // 创建连接实例
							bleSocket = bluetoothSocket;
							plus.android.importClass(bluetoothSocket); // 引入 实例 方便 . 操作
							if (!bleSocket.isConnected()) {
								bleSocket.connect();
							} else {
								bleSocket.close();
								bleSocket.connect();
							}
							/**发送**/
							// let invoke = plus.android.invoke;
							// plus.android.importClass(bleSocket);
							// btOutStream = invoke(bleSocket, "getOutputStream");
							// plus.android.importClass(btOutStream);
							// let bytes = [-96, 4, -1, -119, 1];
							// let btCheck = checkSum(bytes, 0, bytes.length);
							// bytes.push(btCheck);
							// btOutStream.write(bytes);
							/**读**/
							timer = setInterval(this.getMessage, 100);
							obj.innerHTML = "取消盘点";
							// console.log("开始扫描...")
							mui.toast("开始扫描工作...");
						} else {
							bleSocket.close();
							var plusMain = plus.android.runtimeMainActivity(), // Android原生应用的主Activity对象
								BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"), // 引入蓝牙设备操作类
								UUID = plus.android.importClass("java.util.UUID"), // 引入生成UUID类
								// uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
								uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
								BAdapter = BluetoothAdapter.getDefaultAdapter(), // 获得蓝牙适配器实例
								device = BAdapter.getRemoteDevice(connectId); // 以给定的MAC地址去创建一个 BluetoothDevice 类实例(代表远程蓝牙实例)。
							BAdapter.cancelDiscovery();
							plus.android.importClass(device); // 引入 BluetoothDevice 类实例 方便 . 操作
							var bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); // 创建连接实例
							bleSocket = bluetoothSocket;
							plus.android.importClass(bluetoothSocket); // 引入 实例 方便 . 操作
							if (!bleSocket.isConnected()) {
								bleSocket.connect();
							} else {
								bleSocket.close();
								bleSocket.connect();
								// console.log("重新连接成功！")
							}
							/**发送**/
							// let invoke = plus.android.invoke;
							// plus.android.importClass(bleSocket);
							// btOutStream = invoke(bleSocket, "getOutputStream");
							// plus.android.importClass(btOutStream);
							// let bytes = [-96, 4, -1, -119, 1];
							// let btCheck = checkSum(bytes, 0, bytes.length);
							// bytes.push(btCheck);
							// btOutStream.write(bytes);
							/**读**/
							timer = setInterval(this.getMessage, 100);
							obj.innerHTML = "取消盘点";
							// console.log("开始扫描...")
							mui.toast("开始扫描工作...")
						}
					}else{
						timer = null;
						clearInterval(timer);
						obj.innerHTML = "开始盘点";
						// console.log("开始扫描...")
						mui.toast("结束盘点工作...");
					}
				},
				// 扫描标签
				getMessage:function() {
					let invoke = plus.android.invoke;
					plus.android.importClass(bleSocket);
					btOutStream = invoke(bleSocket, "getOutputStream");
					plus.android.importClass(btOutStream);
					let bytes = [-96, 4, -1, -119, 1];
					let btCheck = checkSum(bytes, 0, bytes.length);
					bytes.push(btCheck);
					btOutStream.write(bytes);
					btOutStream.flush();
					// while(timer!=null){
						btInStream = invoke(bleSocket, "getInputStream");
						plus.android.importClass(btInStream);
						let data = invoke(btInStream, "read");
						console.log(data)
						if (dataArr.length === 0) {
							dataArr.push(data);
						} else if (data === 160 && dataArr.length > 0) {
							if (!isInclude([160], dataArr)) {
								dataArr.unshift(data);
							}
							let errCode = [160, 10, 1, 137, 0, 0];
							let err2Code = [160, 86, 32, 3, 24, 0];
							if (!isInclude(errCode, dataArr) && !isInclude(err2Code, dataArr)) {
								// 获取首个0下标
								let zeroIndex = getArrayIndex(dataArr, 0)
								if (zeroIndex.length < 1 && zeroIndex === -1) {
									dataArr = [];
									return;
								}
								console.log(dataArr);
								dataArr = dataArr.splice(zeroIndex[0] + 1, (dataArr.length - zeroIndex[0]) - 3);
								if (this.dataList != null && this.dataList.length > 0) {
									let obj = {
										hex: bytesToHexArr(dataArr),
										arr: dataArr
									}
									let key = 0;
									for (let i = 0; i < this.dataList.length; i++) {
										if (isInclude(obj.arr, this.dataList[i].arr)) {
											key = 1;
											break;
										}
									}
									if (key === 0) {
										if (dataArr.length > 4) {
											// console.log(obj.arr)
											// 将获取的标签数据转为资产数据
											let hexArr = bytesToHexArr(dataArr);
											let assetNum = hex2DataString(hexArr);
											console.log(assetNum);
											getAssetInfo(assetNum, select_active_store);
											setTimeout(function(){
												getAssetInfo(assetNum, select_active_store);
											},10);
											this.dataList.push(obj);
											dataArr = [];
											return;
										}
									}
								} else {
									if (dataArr.length > 4 && this.dataList.length === 0) {
										let obj = {
											hex: bytesToHexArr(dataArr),
											arr: dataArr
										}
										// 将获取的标签数据转为资产数据
										// console.log(obj.arr);
										let hexArr = bytesToHexArr(dataArr);
										let assetNum = hex2DataString(hexArr);
										console.log(assetNum);
										setTimeout(function(){
											getAssetInfo(assetNum, select_active_store);
										},10);
										this.dataList.push(obj);
										dataArr = [];
										return;
									}
								}
							}
							dataArr = [];
						} else {
							dataArr.push(data);
						}
					// }
				},
				// 搜索蓝牙设备
				startBlue: function() {
					// console.log("开始搜索蓝牙设备！")
					mui.toast("开始搜索蓝牙设备...");
					var self = this;
					self.dataList = [];
					if (!self.blue.CheckBluetoothState()) { // 判断是否开启蓝牙
						self.blue.StartBluetooth();
						return;
					}
					self.Pairedlist = [];
					self.isSearch = true;
					// mui('.mui-btn').button('loading');
					self.blue.StartSeatch(function(obj) {
						if (obj !== false) {
							if (obj.BleDevice === null || obj.bleName === null || obj.bleId === null) {
								return;
							}
							let sign = true;
							if (self.Pairedlist.length === 0) {
								self.Pairedlist.push(obj);
								return;
							} else {
								for (let i = 0; i < self.Pairedlist.length; i++) {
									if (obj.bleName === self.Pairedlist[i].bleName) {
										sign = false;
										break;
									}
								}
								if (sign === true) {
									self.Pairedlist.push(obj);
								}
							}
						}
					}, function() {
						self.msg = '搜索蓝牙设备';
						mui('.mui-btn').button('reset');
						self.isSearch = false;
					});
				},
				// 进行配对
				Bluepairing: function(index) {
					if (!this.Pairedlist[index]) {
						mui.toast('设备不存在!');
						return;
					}
					var self = this,
						BleDevice = self.Pairedlist[index].BleDevice,
						bleId = self.Pairedlist[index].bleId;
					mui('.mui-btn').button('loading');
					self.blue.Bluepairing(BleDevice, bleId, function(msg) {
						mui.toast(msg.errmsg);
						self.Pairedlist.push(self.Pairedlist[index]); // 已配对设备新增元素
						// self.Pairedlist.splice(index, 1); // 未配对设备删除元素
						self.msg = '配对结束，重新搜索！';
						mui('.mui-btn').button('reset');
					}, function(msg) {
						mui.toast(msg.errmsg);
						self.msg = '配对结束，重新搜索！';
						mui('.mui-btn').button('reset');
					});
				},
				// 连接设备
				ConnectDevice: function(index) {
					var self = this;
					mui.plusReady(function() {
						var bleId = self.Pairedlist[index].bleId;
						console.log(bleId);
						connectId = bleId;
						var plusMain = plus.android.runtimeMainActivity(), // Android原生应用的主Activity对象
							BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"), // 引入蓝牙设备操作类
							UUID = plus.android.importClass("java.util.UUID"), // 引入生成UUID类
							// uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
							uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
							BAdapter = BluetoothAdapter.getDefaultAdapter(), // 获得蓝牙适配器实例
							device = BAdapter.getRemoteDevice(bleId); // 以给定的MAC地址去创建一个 BluetoothDevice 类实例(代表远程蓝牙实例)。
						connectDevice = device;
						BAdapter.cancelDiscovery();
						plus.android.importClass(device); // 引入 BluetoothDevice 类实例 方便 . 操作
						var bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); // 创建连接实例
						bleSocket = bluetoothSocket;
						plus.android.importClass(bluetoothSocket); // 引入 实例 方便 . 操作
						// 判断是否连接 没有连接则连接
						try {
							if (!bluetoothSocket.isConnected()) {
								bluetoothSocket.connect();
								mui.toast('连接成功！');
							}
						} catch (err) {
							bluetoothSocket.close();
							mui.toast('断开连接！');
						}
					});
				},
				SearchBluetooth: function() {
					/*plus变量定义*/
					var main, BluetoothAdapter, BAdapter, IntentFilter, BluetoothDevice, receiver;
					/*其他定义*/
					var isSearchDevices = false, // 是否处于搜索状态
						debug = false; // 调试模式
					main = plus.android.runtimeMainActivity(),
						BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"),
						IntentFilter = plus.android.importClass('android.content.IntentFilter'),
						BluetoothDevice = plus.android.importClass("android.bluetooth.BluetoothDevice"),
						BAdapter = new BluetoothAdapter.getDefaultAdapter();
					return {
						// 检查蓝牙是否开启
						CheckBluetoothState: function() {
							return BAdapter.isEnabled();
						},
						// 开启蓝牙
						StartBluetooth: function() {
							var self = this;
							if (!BAdapter.isEnabled()) { // isEnabled判断蓝牙状态
								BAdapter.enable(); // 请求开启蓝牙
							}
						},
						// 开始搜索设备
						StartSeatch: function(CallBack, errcallback) {
							// this.Pairedlist = [];
							try {
								var self = this;
								isSearchDevices = true;
								var filter = new IntentFilter(),
									bdevice = new BluetoothDevice();
								BAdapter.startDiscovery(); //开启搜索
								receiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {
									onReceive: onReceiveFn
								});
								filter.addAction(bdevice.ACTION_FOUND);
								filter.addAction(BAdapter.ACTION_DISCOVERY_STARTED);
								filter.addAction(BAdapter.ACTION_DISCOVERY_FINISHED);
								filter.addAction(BAdapter.ACTION_STATE_CHANGED);
								main.registerReceiver(receiver, filter); //注册监听事件
								//监听回调函数  回调函数会在搜索期间 持续调用
								// mui.toast("搜索蓝牙设备中...")
								function onReceiveFn(context, intent) {
									self.msg = "搜索蓝牙设备中...";
									plus.android.importClass(intent); //通过intent实例引入intent类，方便以后的‘.’操作
									//开始搜索改变状态
									intent.getAction() === "android.bluetooth.device.action.FOUND" && (isSearchDevices = true);
									//判断是否搜索结束
									if (intent.getAction() === 'android.bluetooth.adapter.action.DISCOVERY_FINISHED') {
										main.unregisterReceiver(receiver); //取消监听
										isSearchDevices = false;
										errcallback();
										return;
									}
									var BleDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE), // 设备对象
										bleName = BleDevice.getName(), //设备名称
										bleId = BleDevice.getAddress(); //设备mac地址
									if (!bleName || !bleId) {
										CallBack(false);
									}
									let obj = {
										BleDevice: BleDevice,
										bleName: bleName,
										bleId: bleId
									}
									CallBack(obj)
								}
							} catch (err) {
								errcallback();
							}
						},
						// 配对蓝牙设备
						Bluepairing: function(BleDevice, bleId, CallBack, ErrCallBack) {
							try {
								var self = this,
									bdevice = new BluetoothDevice(), // new java android.bluetooth.BluetoothDevice对象
									BleDeviceItem = BleDevice; // 赋值设备
								if (BleDeviceItem.getAddress() === bleId) {
									BleDeviceItem.createBond(); // 设备进行配对
									var timeout = setInterval(function() { // 创建定时器轮询配对结果
										if (BleDeviceItem.getBondState() === bdevice.BOND_BONDED) { // 配对成功
											window.clearInterval(timeout);
											CallBack({
												status: true,
												errmsg: '配对成功'
											});
										} else if (BleDeviceItem.getBondState() === bdevice.BOND_NONE) { // 配对失败
											window.clearInterval(timeout);
											ErrCallBack({
												status: false,
												errmsg: '配对失败,请尝试重新配对'
											});
										}
									}, 1000);
								} else {
									ErrCallBack({
										status: false,
										errmsg: '设备有误'
									});
								}
							} catch (err) {
								ErrCallBack({
									status: false,
									errmsg: '异常错误'
								});
							}
						}
					}
				}
				//// 开始获取版本
				// open_read_firmware: function() {
				// 	if (bleSocket !== null && timer === null) {
				// 		bleSocket.close();
				// 		var plusMain = plus.android.runtimeMainActivity(), // Android原生应用的主Activity对象
				// 			BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"), // 引入蓝牙设备操作类
				// 			UUID = plus.android.importClass("java.util.UUID"), // 引入生成UUID类
				// 			// uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 			uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 			BAdapter = BluetoothAdapter.getDefaultAdapter(), // 获得蓝牙适配器实例
				// 			device = BAdapter.getRemoteDevice(connectId); // 以给定的MAC地址去创建一个 BluetoothDevice 类实例(代表远程蓝牙实例)。
				// 		BAdapter.cancelDiscovery();
				// 		plus.android.importClass(device); // 引入 BluetoothDevice 类实例 方便 . 操作
				// 		var bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); // 创建连接实例
				// 		bleSocket = bluetoothSocket;
				// 		plus.android.importClass(bluetoothSocket); // 引入 实例 方便 . 操作
				// 		// console.log(bleSocket.isConnected())
				// 		if (!bleSocket.isConnected()) {
				// 			bleSocket.connect();
				// 			// console.log("重新连接成功")
				// 		} else {
				// 			bleSocket.close();
				// 			bleSocket.connect();
				// 		}
				// 		let obj = document.getElementById("read_firmware");
				// 		this.firmwareId = null;
				// 		clearInterval(timer);
				// 		timer === null;
				// 		if (timer === null && this.firmwareId === null) {
				// 			timer = setInterval(this.read_firmware, 100);
				// 		}
				// 	} else {
				// 		if (bleSocket === null) {
				// 			// console.log("设备没有连接！");
				// 			mui.toast("设备没有连接！")
				// 			return;
				// 		} else {
				// 			// console.log("不是第一次连接")
				// 			bleSocket.close();
				// 			var plusMain = plus.android.runtimeMainActivity(), // Android原生应用的主Activity对象
				// 				BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"), // 引入蓝牙设备操作类
				// 				UUID = plus.android.importClass("java.util.UUID"), // 引入生成UUID类
				// 				// uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 				uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 				BAdapter = BluetoothAdapter.getDefaultAdapter(), // 获得蓝牙适配器实例
				// 				device = BAdapter.getRemoteDevice(connectId); // 以给定的MAC地址去创建一个 BluetoothDevice 类实例(代表远程蓝牙实例)。
				// 			BAdapter.cancelDiscovery();
				// 			plus.android.importClass(device); // 引入 BluetoothDevice 类实例 方便 . 操作
				// 			var bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); // 创建连接实例
				// 			bleSocket = bluetoothSocket;
				// 			plus.android.importClass(bluetoothSocket); // 引入 实例 方便 . 操作
				// 			// console.log(bleSocket.isConnected())
				// 			if (!bleSocket.isConnected()) {
				// 				bleSocket.connect();
				// 			} else {
				// 				bleSocket.close();
				// 				bleSocket.connect();
				// 			}
				// 			let obj = document.getElementById("read_firmware");
				// 			this.firmwareId = null;
				// 			clearInterval(timer);
				// 			timer === null;
				// 			if (timer === null && this.firmwareId === null) {
				// 				timer = setInterval(this.read_firmware, 100);
				// 			}
				// 		}
				// 	}
				// },
				// //获取固件版本
				// read_firmware: function() {
				// 	let invoke = plus.android.invoke;
				// 	var os = invoke(bleSocket, "getOutputStream");
				// 	console.log("获取固件版本:");
				// 	let dataArr = new Array();
				// 	while (1) {
				// 		plus.android.importClass(bleSocket);
				// 		let bytes = [-96, 3, 1, 114, -22];
				// 		plus.android.importClass(os);
				// 		var oi = invoke(bleSocket, "getInputStream");
				// 		plus.android.importClass(oi);
				// 		this.firmwareId = null;
				// 		os.write(bytes);
				// 		let data = invoke(oi, "read");
				// 		dataArr.push(data);
				// 		if (data === 160 && dataArr.length > 1) {
				// 			for (var i = 0; i < dataArr.length; i++) {
				// 				if (dataArr[i] === 160) {
				// 					dataArr.splice(i, 1);
				// 					break;
				// 				}
				// 			}
				// 			dataArr.unshift(160);
				// 			// 获取版本个位
				// 			// console.log(dataArr)
				// 			// 获取主版本号
				// 			let bit = dataArr[4];
				// 			// console.log(bit)
				// 			// 后去次版本号
				// 			let dec = dataArr[5] / 10;
				// 			// 获取版本小数
				// 			this.firmwareId = Math.round(bit) + dec
				// 			// console.log(this.firmwareId)
				// 			if (this.firmwareId !== null) {
				// 				mui.toast("版本固件版本为：" + this.firmwareId)
				// 				clearInterval(timer);
				// 				timer = null;
				// 				return;
				// 			}
				// 			dataArr = [];
				// 			return;
				// 		}
				// 	}
				// },
				// // 开始获取温度
				// open_read_temperature: function() {
				// 	if (bleSocket !== null && timer === null) {
				// 		bleSocket.close();
				// 		var plusMain = plus.android.runtimeMainActivity(), // Android原生应用的主Activity对象
				// 			BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"), // 引入蓝牙设备操作类
				// 			UUID = plus.android.importClass("java.util.UUID"), // 引入生成UUID类
				// 			// uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 			uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 			BAdapter = BluetoothAdapter.getDefaultAdapter(), // 获得蓝牙适配器实例
				// 			device = BAdapter.getRemoteDevice(connectId); // 以给定的MAC地址去创建一个 BluetoothDevice 类实例(代表远程蓝牙实例)。
				// 		BAdapter.cancelDiscovery();
				// 		plus.android.importClass(device); // 引入 BluetoothDevice 类实例 方便 . 操作
				// 		var bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); // 创建连接实例
				// 		bleSocket = bluetoothSocket;
				// 		plus.android.importClass(bluetoothSocket); // 引入 实例 方便 . 操作
				// 		// console.log(bleSocket.isConnected())
				// 		if (!bleSocket.isConnected()) {
				// 			bleSocket.connect();
				// 			// console.log("重新连接成功")
				// 		} else {
				// 			bleSocket.close();
				// 			bleSocket.connect();
				// 		}
				// 		this.temperature = null;
				// 		clearInterval(timer);
				// 		timer === null;
				// 		if (timer === null && this.temperature === null) {
				// 			timer = setInterval(this.read_temperature, 100);
				// 		}
				// 	} else {
				// 		if (bleSocket === null) {
				// 			// console.log("设备没有连接！");
				// 			mui.toast("设备没有链接！")
				// 			return;
				// 		} else {
				// 			bleSocket.close();
				// 			var plusMain = plus.android.runtimeMainActivity(), // Android原生应用的主Activity对象
				// 				BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"), // 引入蓝牙设备操作类
				// 				UUID = plus.android.importClass("java.util.UUID"), // 引入生成UUID类
				// 				// uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 				uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 				BAdapter = BluetoothAdapter.getDefaultAdapter(), // 获得蓝牙适配器实例
				// 				device = BAdapter.getRemoteDevice(connectId); // 以给定的MAC地址去创建一个 BluetoothDevice 类实例(代表远程蓝牙实例)。
				// 			BAdapter.cancelDiscovery();
				// 			plus.android.importClass(device); // 引入 BluetoothDevice 类实例 方便 . 操作
				// 			var bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); // 创建连接实例
				// 			bleSocket = bluetoothSocket;
				// 			plus.android.importClass(bluetoothSocket); // 引入 实例 方便 . 操作
				// 			// console.log(bleSocket.isConnected())
				// 			if (!bleSocket.isConnected()) {
				// 				bleSocket.connect();
				// 			} else {
				// 				bleSocket.close();
				// 				bleSocket.connect();
				// 			}
				// 			this.temperature = null;
				// 			clearInterval(timer);
				// 			timer === null;
				// 			if (timer === null && this.temperature === null) {
				// 				timer = setInterval(this.read_temperature, 100);
				// 			}
				// 		}
				// 	}
				// },
				// //获取设备工作温度
				// read_temperature: function() {
				// 	try {
				// 		let invoke = plus.android.invoke;
				// 		var os = invoke(bleSocket, "getOutputStream");
				// 		// console.log("获取设备工作温度:");
				// 		let dataArr = new Array();
				// 		while (1) {
				// 			plus.android.importClass(bleSocket);
				// 			let bytes = [-96, 3, -1, 123, -29]; // 温度上位机代码
				// 			plus.android.importClass(os);
				// 			var oi = invoke(bleSocket, "getInputStream");
				// 			plus.android.importClass(oi);
				// 			this.temperature = null;
				// 			os.write(bytes);
				// 			// os.flush();
				// 			let data = invoke(oi, "read");
				// 			dataArr.push(data);
				// 			if (data === 160 && dataArr.length > 1) {
				// 				for (var i = 0; i < dataArr.length; i++) {
				// 					if (dataArr[i] === 160) {
				// 						dataArr.splice(i, 1);
				// 						break;
				// 					}
				// 				}
				// 				dataArr.unshift(160);
				// 				//获取是否为零上温度(0为零下，1为零上)
				// 				let positive = dataArr[4];
				// 				// 获取温度数
				// 				// console.log(dataArr)
				// 				let bit = dataArr[5];
				// 				if (positive !== 1) {
				// 					bit = 0 - bit;
				// 				}
				// 				this.temperature = Math.round(bit) + "℃";
				// 				if (this.temperature !== null) {
				// 					mui.toast("工作温度为:" + this.temperature);
				// 					clearInterval(timer);
				// 					timer = null;
				// 					return;
				// 				}
				// 				dataArr = [];
				// 				return;
				// 			}
				// 		}
				// 	} catch (err) {
				// 		// console.log(err + "获取设备温度失败！");
				// 		mui.toast("获取设别温度失败！")
				// 	}
				// },
				// // 开始读取标签
				// open_read_lable: function() {
				// 	if (this.is_select === false) {
				// 		// console.log("未选取标签，请选取标签！")
				// 		mui.toast("未选取标签，请选取标签！")
				// 		return;
				// 	}
				// 	mui.toast("读取标签信息！")
				// 	if (bleSocket !== null && timer === null) {
				// 		bleSocket.close();
				// 		var plusMain = plus.android.runtimeMainActivity(), // Android原生应用的主Activity对象
				// 			BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"), // 引入蓝牙设备操作类
				// 			UUID = plus.android.importClass("java.util.UUID"), // 引入生成UUID类
				// 			// uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 			uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 			BAdapter = BluetoothAdapter.getDefaultAdapter(), // 获得蓝牙适配器实例
				// 			device = BAdapter.getRemoteDevice(connectId); // 以给定的MAC地址去创建一个 BluetoothDevice 类实例(代表远程蓝牙实例)。
				// 		BAdapter.cancelDiscovery();
				// 		plus.android.importClass(device); // 引入 BluetoothDevice 类实例 方便 . 操作
				// 		var bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); // 创建连接实例
				// 		bleSocket = bluetoothSocket;
				// 		plus.android.importClass(bluetoothSocket); // 引入 实例 方便 . 操作
				// 		if (!bleSocket.isConnected()) {
				// 			bleSocket.connect();
				// 		} else {
				// 			bleSocket.close();
				// 			bleSocket.connect();
				// 		}
				// 		this.read_lableId = null;
				// 		clearInterval(timer);
				// 		timer = null;
				// 		if (timer === null && this.read_lableId === null) {
				// 			timer = setInterval(this.read_lable, 100);
				// 		}
				// 	} else {
				// 		if (bleSocket === null) {
				// 			// console.log("设备没有连接！");
				// 			mui.toast("设备没有连接！选取失败！")
				// 			return;
				// 		} else {
				// 			bleSocket.close();
				// 			var plusMain = plus.android.runtimeMainActivity(), // Android原生应用的主Activity对象
				// 				BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"), // 引入蓝牙设备操作类
				// 				UUID = plus.android.importClass("java.util.UUID"), // 引入生成UUID类
				// 				// uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 				uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 				BAdapter = BluetoothAdapter.getDefaultAdapter(), // 获得蓝牙适配器实例
				// 				device = BAdapter.getRemoteDevice(connectId); // 以给定的MAC地址去创建一个 BluetoothDevice 类实例(代表远程蓝牙实例)。
				// 			BAdapter.cancelDiscovery();
				// 			plus.android.importClass(device); // 引入 BluetoothDevice 类实例 方便 . 操作
				// 			var bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); // 创建连接实例
				// 			bleSocket = bluetoothSocket;
				// 			plus.android.importClass(bluetoothSocket); // 引入 实例 方便 . 操作
				// 			if (!bleSocket.isConnected()) {
				// 				bleSocket.connect();
				// 			} else {
				// 				bleSocket.close();
				// 				bleSocket.connect();
				// 			}
				// 			this.read_lableId = null;
				// 			clearInterval(timer);
				// 			timer = null;
				// 			if (timer === null && this.read_lableId === null) {
				// 				timer = setInterval(this.read_lable, 100);
				// 			}
				// 		}
				// 	}
				// },
				// // 读取标签
				// read_lable: function() {
				// 	try {
				// 		// 注册输入输出流
				// 		let invoke = plus.android.invoke;
				// 		btOutStream = invoke(bleSocket, "getOutputStream");
				// 		plus.android.importClass(bleSocket);
				// 		let bytes = [-96, 10, 1, -127, 1, 2, 6, 0, 0, 0, 0];
				// 		let btCheck = checkSum(bytes, 0, bytes.length);
				// 		bytes.push(btCheck);
				// 		console.log("读取标签：" + bytes);
				// 		plus.android.importClass(btOutStream);
				// 		let dataArr = new Array();
				// 		// 返回标签数据
				// 		try {
				// 			btInStream = invoke(bleSocket, "getInputStream");
				// 			plus.android.importClass(btInStream);
				// 			while (1) {
				// 				btOutStream.write(bytes);
				// 				// btOutStream.flush();
				// 				let data = invoke(btInStream, "read");
				// 				if (data === 160 && dataArr.length > 1) {
				// 					this.read_lableId = bytesToHexArr(dataArr);
				// 					if (this.read_lableId !== null) {
				// 						console.log(this.read_lableId);
				// 						this.is_select = false;
				// 						dataArr.length = [];
				// 						clearInterval(timer);
				// 						timer = null;
				// 						return;
				// 					}
				// 				} else {
				// 					dataArr.push(data);
				// 				}
				// 			}
				// 		} catch (err) {
				// 			console.log(err);
				// 		}
				// 	} catch (err) {
				// 		// console.log("读取标签失败！")
				// 		mui.toast("读取标签失败！")
				// 	}
				// },
				// // 开始选中标签
				// open_select_lable: function(arr) {
				// 	if (this.is_select === true) {
				// 		// console.log("已选取标签，请读取标签数据或编辑标签数据！")
				// 		mui.toast("已选取标签，请对标签进行操作！");
				// 		return;
				// 	}
				// 	arr = ifB127SF128(arr);
				// 	// console.log(arr)
				// 	// console.log(this.select_lableId)
				// 	if (timer !== null) {
				// 		clearInterval(timer);
				// 		timer = null;
				// 		this.open_select_lable();
				// 	} else {
				// 		if (bleSocket !== null && timer === null) {
				// 			bleSocket.close();
				// 			var plusMain = plus.android.runtimeMainActivity(), // Android原生应用的主Activity对象
				// 				BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"), // 引入蓝牙设备操作类
				// 				UUID = plus.android.importClass("java.util.UUID"), // 引入生成UUID类
				// 				// uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 				uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 				BAdapter = BluetoothAdapter.getDefaultAdapter(), // 获得蓝牙适配器实例
				// 				device = BAdapter.getRemoteDevice(connectId); // 以给定的MAC地址去创建一个 BluetoothDevice 类实例(代表远程蓝牙实例)。
				// 			BAdapter.cancelDiscovery();
				// 			plus.android.importClass(device); // 引入 BluetoothDevice 类实例 方便 . 操作
				// 			var bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); // 创建连接实例
				// 			bleSocket = bluetoothSocket;
				// 			plus.android.importClass(bluetoothSocket); // 引入 实例 方便 . 操作
				// 			if (!bleSocket.isConnected()) {
				// 				bleSocket.connect();
				// 			} else {
				// 				bleSocket.close();
				// 				bleSocket.connect();
				// 			}
				// 			this.select_lableId = null;
				// 			clearInterval(timer);
				// 			timer = null;
				// 			if (timer === null && this.select_lableId === null) {
				// 				timer = setInterval(this.select_lable(arr), 100);
				// 			}
				// 		} else {
				// 			if (bleSocket === null) {
				// 				// console.log("设备没有连接！");
				// 				mui.toast("设备没有连接！");
				// 				return;
				// 			} else {
				// 				bleSocket.close();
				// 				var plusMain = plus.android.runtimeMainActivity(), // Android原生应用的主Activity对象
				// 					BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"), // 引入蓝牙设备操作类
				// 					UUID = plus.android.importClass("java.util.UUID"), // 引入生成UUID类
				// 					// uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 					uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 					BAdapter = BluetoothAdapter.getDefaultAdapter(), // 获得蓝牙适配器实例
				// 					device = BAdapter.getRemoteDevice(connectId); // 以给定的MAC地址去创建一个 BluetoothDevice 类实例(代表远程蓝牙实例)。
				// 				BAdapter.cancelDiscovery();
				// 				plus.android.importClass(device); // 引入 BluetoothDevice 类实例 方便 . 操作
				// 				var bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); // 创建连接实例
				// 				bleSocket = bluetoothSocket;
				// 				plus.android.importClass(bluetoothSocket); // 引入 实例 方便 . 操作
				// 				if (!bleSocket.isConnected()) {
				// 					bleSocket.connect();
				// 				} else {
				// 					bleSocket.close();
				// 					bleSocket.connect();
				// 				}
				// 				this.select_lableId = null;
				// 				clearInterval(timer);
				// 				timer = null;
				// 				if (timer === null && this.select_lableId === null) {
				// 					timer = setInterval(this.select_lable(arr), 100);
				// 				}
				// 			}
				// 		}
				// 	}
				// },
				// // 选取标签
				// select_lable: function(arr) {
				// 	try {
				// 		let invoke = plus.android.invoke;
				// 		var os = invoke(bleSocket, "getOutputStream");
				// 		console.log("开始选中标签:" + arr);
				// 		// hexArr2String(arr);
				// 		mui.toast("开始选中标签:" + bytesToHexArr(arr));
				// 		let dataArr = new Array();
				// 		while (1) {
				// 			plus.android.importClass(bleSocket);
				// 			let sign = [-96, 17, -1, -123, 0, 12];
				// 			// let lableId = [23, 32, 86, 32, 9, 18 , 0, 0, 0, 0, 0, 0];
				// 			// 获取标签上位机代码
				// 			let bytes = new Array();
				// 			for (let i = 0; i < sign.length; i++) {
				// 				bytes.push(sign[i]);
				// 			}
				// 			for (let j = 0; j < arr.length; j++) {
				// 				console.log(arr[j]);
				// 				bytes.push(arr[j]);
				// 			}
				// 			let btCheck = checkSum(bytes, 0, bytes.length);
				// 			bytes.push(btCheck);
				// 			// console.log(bytes)
				// 			// console.log(bytes)
				// 			// console.log(bytesToHexArr(bytes));
				// 			plus.android.importClass(os);
				// 			var oi = invoke(bleSocket, "getInputStream");
				// 			plus.android.importClass(oi);
				// 			this.select_lableId = null;
				// 			os.write(bytes);
				// 			// os.flush();
				// 			let data = invoke(oi, "read");
				// 			// console.log(data)
				// 			if (data === 160 && dataArr.length > 1) {
				// 				// console.log(dataArr)
				// 				// console.log(bytesToHexArr(dataArr))

				// 				this.select_lableId = dataArr;
				// 				if (this.select_lableId !== null) {
				// 					this.is_select = true;
				// 					// console.log("选取标签成功 ：" + arr)
				// 					mui.toast("选取标签成功:" + bytesToHexArr(arr));
				// 					console.log(bytesToHexArr(arr));
				// 					dataArr = [];
				// 					clearInterval(timer);
				// 					timer = null;
				// 					return;
				// 				}
				// 			} else {
				// 				dataArr.push(data);
				// 			}
				// 		}
				// 	} catch (err) {
				// 		// console.log(err + "选取标签失败！");
				// 		mui.toast("选取标签失败！")
				// 	}
				// },
				// // 开始写入标签
				// open_set_lable: function(str) {
				// 	console.log(this.set_lableId)
				// 	if (timer !== null) {
				// 		clearInterval(timer);
				// 		timer = null;
				// 		this.open_set_lable();
				// 	} else {
				// 		if (bleSocket !== null && timer === null) {
				// 			bleSocket.close();
				// 			var plusMain = plus.android.runtimeMainActivity(), // Android原生应用的主Activity对象
				// 				BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"), // 引入蓝牙设备操作类
				// 				UUID = plus.android.importClass("java.util.UUID"), // 引入生成UUID类
				// 				// uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 				uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 				BAdapter = BluetoothAdapter.getDefaultAdapter(), // 获得蓝牙适配器实例
				// 				device = BAdapter.getRemoteDevice(connectId); // 以给定的MAC地址去创建一个 BluetoothDevice 类实例(代表远程蓝牙实例)。
				// 			BAdapter.cancelDiscovery();
				// 			plus.android.importClass(device); // 引入 BluetoothDevice 类实例 方便 . 操作
				// 			var bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); // 创建连接实例
				// 			bleSocket = bluetoothSocket;
				// 			plus.android.importClass(bluetoothSocket); // 引入 实例 方便 . 操作
				// 			if (!bleSocket.isConnected()) {
				// 				bleSocket.connect();
				// 			} else {
				// 				bleSocket.close();
				// 				bleSocket.connect();
				// 			}
				// 			this.set_lableId = null;
				// 			clearInterval(timer);
				// 			timer = null;
				// 			if (timer === null && this.set_lableId === null) {
				// 				timer = setInterval(this.set_lable(arr), 100);
				// 			}
				// 		} else {
				// 			if (bleSocket === null) {
				// 				// console.log("设备没有连接！");
				// 				mui.toast("设备没有连接！")
				// 				return;
				// 			} else {
				// 				bleSocket.close();
				// 				var plusMain = plus.android.runtimeMainActivity(), // Android原生应用的主Activity对象
				// 					BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"), // 引入蓝牙设备操作类
				// 					UUID = plus.android.importClass("java.util.UUID"), // 引入生成UUID类
				// 					// uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 					uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"), // 生成UUIID
				// 					BAdapter = BluetoothAdapter.getDefaultAdapter(), // 获得蓝牙适配器实例
				// 					device = BAdapter.getRemoteDevice(connectId); // 以给定的MAC地址去创建一个 BluetoothDevice 类实例(代表远程蓝牙实例)。
				// 				BAdapter.cancelDiscovery();
				// 				plus.android.importClass(device); // 引入 BluetoothDevice 类实例 方便 . 操作
				// 				var bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); // 创建连接实例
				// 				bleSocket = bluetoothSocket;
				// 				plus.android.importClass(bluetoothSocket); // 引入 实例 方便 . 操作
				// 				if (!bleSocket.isConnected()) {
				// 					bleSocket.connect();
				// 				} else {
				// 					bleSocket.close();
				// 					bleSocket.connect();
				// 				}
				// 				this.set_lableId = null;
				// 				clearInterval(timer);
				// 				timer = null;
				// 				if (timer === null && this.select_lableId === null) {
				// 					timer = setInterval(this.set_lable(arr), 100);
				// 				}
				// 			}
				// 		}
				// 	}
				// },
				// // 写入标签
				// set_lable: function(str) {
				// 	try {
				// 		let invoke = plus.android.invoke;
				// 		var os = invoke(bleSocket, "getOutputStream");
				// 		let dataArr = new Array();
				// 		str = "12007304";
				// 		console.log("写入标签:" + str);
				// 		// arr = ifB127SF128(arr);
				// 		while (1) {
				// 			plus.android.importClass(bleSocket);
				// 			let sign = [-96, 15, 1, -126, 0, 0, 0, 0, 1, 2, 3];
				// 			// 将写入的数据进行处理 // -96,15,1,-126,0,0,0,0,1,2,3,4,18,0,115,4,59
				// 			// -96 15 1 -126 0 0 0 0 1 2 3 4 18 0 115 4 59
				// 			let arr = setLable(str);
				// 			for (let dd = 0; dd < arr.length; dd++) {
				// 				console.log(typeof arr[dd]);
				// 			}
				// 			// 设置上位机字节流
				// 			let bytes = new Array();
				// 			for (let i = 0; i < sign.length; i++) {
				// 				bytes.push(sign[i]);
				// 			}
				// 			for (let j = 0; j < arr.length; j++) {
				// 				bytes.push(arr[j]);
				// 			}
				// 			// 计算天线值
				// 			let btCheck = checkSum(bytes, 0, bytes.length);
				// 			bytes.push(btCheck);
				// 			console.log(bytes);
				// 			plus.android.importClass(os);
				// 			var oi = invoke(bleSocket, "getInputStream");
				// 			plus.android.importClass(oi);
				// 			this.select_lableId = null;
				// 			os.write(bytes);
				// 			// os.flush();
				// 			let data = invoke(oi, "read");
				// 			// console.log(data)
				// 			if (data === 160 && dataArr.length > 1) {
				// 				this.set_lableId = dataArr;
				// 				if (this.set_lableId !== null) {
				// 					console.log("写入标签成功 ：" + str)
				// 					this.is_select = false;
				// 					dataArr = [];
				// 					clearInterval(timer);
				// 					timer = null;
				// 					return;
				// 				}
				// 			} else {
				// 				dataArr.push(data);
				// 			}
				// 		}
				// 	} catch (err) {
				// 		console.log(err + "写入标签失败！");
				// 	}
				// },
				// // 复位读写器
				// reset: function() {
				// 	try {
				// 		if (bleSocket === null) {
				// 			// console.log("复位失败！设备未连接！");
				// 			mui.toast("复位失败！设备未连接！")
				// 			return;
				// 		}
				// 		let invoke = plus.android.invoke;
				// 		btOutStream = invoke(bleSocket, "getOutputStream");
				// 		plus.android.importClass(bleSocket);
				// 		// let head = -96; //0xA0
				// 		// let len = 3; //0x03
				// 		// let address = -1; //0xFF
				// 		// let cmd = 112; //0x70
				// 		// let check = -18; //0xEE
				// 		let bytes = [-96, 3, -1, 112, -18];
				// 		// console.log("复位:" + bytes);
				// 		plus.android.importClass(btOutStream);
				// 		btOutStream.write(bytes);
				// 		btOutStream.flush();
				// 		// console.log("复位成功！");
				// 		mui.toast("复位成功！");
				// 	} catch (err) {
				// 		// console.log(err + "复位失败！");
				// 		mui.toast("复位异常！")
				// 	}
				//}
			},
			// 初始化
			mounted: function() {
				// 初始化创建对象
				var self = this;
				mui.plusReady(function() {
					self.blue = new self.SearchBluetooth();
				});
			}
		})
	})
</script>
